'''学生系统核心代码'''

from lib import common
from interface import student_iface

stu_func_menu = '''
========== 学生系统 ==========
        1.登录
        2.注册
        3.选择课程
        4.查看成绩
        q.退出输入【q】
=============================
'''


def stu_login():
    username, password = common.login_input()
    msg = student_iface.login(username=username, password=password)
    print(msg)


def stu_register():
    username, password = common.login_input()
    msg = student_iface.register(username=username, password=password)
    print(msg)


@common.auth('student')
def select_course():
    flag, school_id = common.select_school()
    if not flag:
        print(school_id)
        return False
    flag, course_id = common.select_course(school_id=school_id)
    if not flag:
        print(course_id)
        return False
    msg = student_iface.select_course(course_id=course_id)
    print(msg)


@common.auth('student')
def check_score():
    msg = student_iface.check_score()
    print(msg)


stu_menu_dict = {
    '1': stu_login,
    '2': stu_register,
    '3': select_course,
    '4': check_score
}


def main():
    while True:
        print(stu_func_menu)
        func_choice = input("请输入功能ID:").strip()
        if func_choice.upper() == 'Q':
            print('【已退出学生系统】')
            break
        elif func_choice not in stu_menu_dict:
            print('【功能ID有误】')
        else:
            stu_menu_dict[func_choice]()
